package ro.sergiu.finder.models.columns;

import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import ro.sergiu.finder.columns.DefaultResultColumnFormatter;
import ro.sergiu.finder.columns.ResultColumnFormatter;

/**
 * Configurations for a result column
 *
 * @author toporjinschi
 * @param <M>
 */
public class ColumnModel<M> {

    public static final int NOT_DEFINED_WIDTH = -1;

    private int width = NOT_DEFINED_WIDTH;
    private int preferredWidth = NOT_DEFINED_WIDTH;
    private int minWidth = NOT_DEFINED_WIDTH;
    private int maxWidth = NOT_DEFINED_WIDTH;
    private M mapItem;
    private String columnName;
    private boolean visible = true;
    private ResultColumnFormatter formatter = new DefaultResultColumnFormatter();
    private TableCellRenderer tableCellRenderer = new DefaultTableCellRenderer();

    public ColumnModel(M mapItem, String columnName, ResultColumnFormatter formatter) {
        this(mapItem, columnName);
        this.formatter = formatter;
    }

    public ColumnModel(M mapItem, String columnName, boolean visible) {
        this(mapItem, columnName);
        this.visible = visible;
    }

    public ColumnModel(M mapItem, String columnName) {
        this.mapItem = mapItem;
        this.columnName = columnName;
    }

    public M getMapItem() {
        return mapItem;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String colName) {
        this.columnName = colName;
    }

    public boolean isVisible() {
        return visible;
    }

    public ResultColumnFormatter getFormatter() {
        return formatter;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    public void setFormatter(ResultColumnFormatter formatter) {
        this.formatter = formatter;
    }

    public TableCellRenderer getTableCellRenderer() {
        return tableCellRenderer;
    }

    public void setTableCellRenderer(TableCellRenderer tableCellRenderer) {
        this.tableCellRenderer = tableCellRenderer;
    }

    public int getWidth() {
        return width;
    }

    public int getPreferredWidth() {
        return preferredWidth;
    }

    public int getMinWidth() {
        return minWidth;
    }

    public int getMaxWidth() {
        return maxWidth;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public void setPreferredWidth(int preferredWidth) {
        this.preferredWidth = preferredWidth;
    }

    public void setMinWidth(int minWidth) {
        this.minWidth = minWidth;
    }

    public void setMaxWidth(int maxWidth) {
        this.maxWidth = maxWidth;
    }

    public ColumnModel setDimension(int width, int preferredWidth, int minWidth, int maxWidth) {
        this.width = width;
        this.preferredWidth = preferredWidth;
        this.minWidth = minWidth;
        this.maxWidth = maxWidth;
        return this;
    }

}
